import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/font/iconfont.css";
import axios from "axios";
import VueAxios from "vue-axios";
import Cookies from "js-cookie";
import {topTips} from "./util/promptbox";
import i18n from './i18n/i18n';
// Vue.config.productionTip = false

Vue.use(VueAxios,axios);
Vue.use(ElementUI);
Vue.config.productionTip = false;
axios.defaults.baseURL = "http://192.168.1.188:8080/";

Vue.prototype.topTips =topTips//全局引用


// 注册一个全局自定义指令 `v-permission` 角色更新
Vue.directive('permission', {
  // 当被绑定的元素插入到 DOM 中时……
  inserted: function (el,binding) {
    // 聚焦元素
    let info = JSON.parse(Cookies.get("info"));
    let data =info.data.data.perms
    for (const i in data) {
      if (binding.value==data[i]) {
        return 
      }
    }
    el.remove()
  }
})





//全局守卫鉴权进入
router.beforeEach((to, from, next) => {
  var routeName = to.name;
  // // 登录页面不用鉴权
  if ("Login" === routeName) {
    next();
  } else {
    var token = Cookies.get("data");
    if (token) {
      next();//有令牌可以进入
    } else {
      var returnUrl = to.fullPath;
      next('/login?returnUrl=' + returnUrl);//返回登录授权，并且记录需要返回的路由然后去登录获取它
    }
  }
})

window.app=new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App),
}).$mount("#app");
